package com.yugao.fintech.antelope.system.service.impl;

import com.yugao.fintech.antelope.system.service.SysMenuService;
import com.yugao.fintech.antelope.system.service.SysPermissionService;
import com.yugao.fintech.antelope.system.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
public class SysPermissionServiceImpl implements SysPermissionService {
    @Autowired
    private SysRoleService roleService;
    @Autowired
    private SysMenuService menuDataService;

    @Override
    public Set<String> listUserRolePermission(Boolean isAdmin, Long userId) {
        Set<String> roles = new HashSet<>();
        // 管理员拥有所有权限
        if (isAdmin) {
            roles.add("admin");
        } else {
            roles.addAll(roleService.listRolePermission(userId));
        }
        return roles;
    }

    @Override
    public Set<String> getMenuPermission(boolean isAdmin, Long userId) {
        Set<String> perms = new HashSet<>();
        // 管理员拥有所有权限
        if (isAdmin) {
            perms.add("*:*:*");
        } else {
            perms.addAll(menuDataService.listMenuPermsByUserId(userId));
        }
        return perms;
    }
}
